package _2响应头;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/test2")
public class Test2Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setHeader("username","zhangsan");
        resp.setHeader("age","18");

        //方式一跳转
      //  resp.setStatus(302);
       // resp.setHeader("location","https://www.baidu.com");

        //方式2 6秒后跳转
       // resp.setHeader("refresh","6,url=https:www.baidu.com");

        //方式3
        //resp.sendRedirect("https://www.baidu.com");


        //设置中文可以显示
        resp.setHeader("Content-Type","text/html;charset=utf-8");

        resp.getWriter().println("中文test");

    }
}
